﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ece750project
{
    public partial class Form1 : Form
    {
		
        //DB_BusinessRules DB;
		DBUtility DBU;
		static int x1(string s)
		{
			MessageBox.Show(s);
			return 0;
		}
		
		int x2(string s)
		{
			MessageBox.Show(s +"/ Heloo the second");
				
			return 0;
		}

		public Form1()
        {
            InitializeComponent();
            //DB = new DB_BusinessRules();
        }

    

     

        private void Form1_Load(object sender, EventArgs e)
        {
            DBU = new DBUtility();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!DBU.Login(txtusername.Text, txtpassword.Text))
            {
                MessageBox.Show("Connection faild");
            }
            else
            {
                btnLogin.Enabled = false;
            }

            System.Media.SystemSounds.Beep.Play();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtpassword_KeyUp(object sender, KeyEventArgs e)
        {

        }

        private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnLogin_Click(sender, e);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DBU.Set_Session_Var("UserName", "'saud'");
            DBU.Set_Session_Var("UserPassWord", "'ils'");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string SQL;
            SQL="UPDATE person set person.first_name = 'Ali'"+
            "WHERE person.person_id=9";
            this.Text= Convert.ToString( DBU.ExcuteSQL(SQL,null));
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Text = DBU.Get_Session_Var("username");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            DB_structure_gen.VBScriptGenerator DBG = new DB_structure_gen.VBScriptGenerator ();
            string connectionString = "server=192.168.1.56;User Id=ece750project;database=abc;password=Database;Persist Security Info=True;Allow User Variables=True; Convert Zero Datetime=true;";
            MySql.Data.MySqlClient.MySqlConnection dbconn1;

            dbconn1 = new MySql.Data.MySqlClient.MySqlConnection(connectionString);
            dbconn1.Open();
            DataTable DT = dbconn1.GetSchema();
            
            object obj = dbconn1;
            connectionString= DBG.Generate_Database_VBCode(ref obj , DB_structure_gen.VBScriptGenerator.DBMSEnum.MySQL);
            int doc_id = 1;
            DBU.call_func("add_doc_permission", doc_id.ToString(), "2", "2", "3");

        }
    }
}
